package com.puffer.core.controller;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;

/**
 * 基础控制器，存放一些全局变量和通用操作
 * 
 * @author ghoul_000
 *
 */
public class baseController {
	@Autowired
	protected HttpServletRequest request;
	
	@Autowired
	protected HttpServletResponse response;

	@Autowired
	protected HttpSession session;

	/**
	 * 无参构造器，用于初始化一些信息 cookies，session，缓存等
	 */
	public baseController() {
		initSession();
		initCache();
	}

	/**
	 * 初始化session
	 */
	private void initSession() {
//		if (request != null) {
//			session = request.getSession();
//		}
	}

	private void initCache() {

	}

	/**
	 * 从cookie中获取key的内容，如果没有获取到则返回false，否则返回真
	 * 
	 * @param userId
	 * @return true:cookie中有该;key false:cookie中没有该key
	 */
	protected boolean FechCookies(String key, String val) {
		Cookie cookies[] = request.getCookies();
		for (Cookie cookie : cookies) {
			if (key.equals(cookie.getName())) {
				if (val.equals(cookie.getValue())) {
					return true;
				}
			}
		}
		return false;
	}
}
